import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';
import { getPopupContainer } from '@vben/utils';

import { getDictOptions } from '#/utils/dict';
import { renderDict, renderTags } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'postName',
    label: '岗位名称',
    hideLabel: true,
    componentProps: {
      placeholder: '请输入岗位名称',
    },
  },
  {
    component: 'Select',
    fieldName: 'status',
    label: '状态',
    hideLabel: true,
    componentProps: {
      optionFilterProp: 'label',
      getPopupContainer,
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
      placeholder: '请选择岗位状态',
    },
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    align: 'center',
    type: 'checkbox',
    width: 45,
    resizable: false,
  },
  {
    title: '岗位名称/标识/类别',
    field: 'postCode',
    minWidth: 200,
    slots: {
      default: ({ row }) => {
        return renderTags(
          [
            { tagName: row.postName || '无名称', tagColor: '#f50' },
            { tagName: row.postCode || '无标识', tagColor: '#108ee9' },
            { tagName: row.postCategory || '无类别', tagColor: 'default' },
          ],
          false,
          5,
        );
      },
    },
  },
  {
    title: '排序',
    align: 'center',
    minWidth: 80,
    width: 80,
    field: 'postSort',
  },
  {
    title: '状态',
    field: 'status',
    align: 'center',
    minWidth: 80,
    width: 80,
    slots: {
      default: ({ row }) => {
        return renderDict(row.status, DictEnum.SYS_NORMAL_DISABLE);
      },
    },
  },
  // {
  //   field: 'createTime',
  //   title: '创建时间',
  //   align: 'center',
  //   minWidth: 160,
  //   width: 160,
  // },
  {
    field: 'action',
    fixed: 'right',
    align: 'center',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'postId',
    label: 'postId',
  },
  {
    component: 'TreeSelect',
    componentProps: {
      getPopupContainer,
    },
    fieldName: 'deptId',
    label: '所属部门',
    rules: 'selectRequired',
  },
  {
    component: 'Input',
    fieldName: 'postName',
    label: '岗位名称',
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'postCode',
    label: '岗位标识',
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'postCategory',
    label: '类别编码',
  },
  {
    component: 'InputNumber',
    fieldName: 'postSort',
    label: '岗位排序',
    rules: 'required',
    defaultValue: 0,
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
      optionType: 'button',
    },
    defaultValue: '0',
    fieldName: 'status',
    label: '岗位状态',
    rules: 'required',
  },
  {
    component: 'Textarea',
    fieldName: 'remark',
    formItemClass: 'items-start',
    label: '备注描述',
    componentProps: {
      placeholder: '请输入备注描述',
      autosize: true,
    },
  },
];
